
<%@ include file="/common/taglibs.jsp"%>
<!--分页查询共用的页面-->
<%@ include file="/common/common.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<script type="text/javascript" src="<%=jsPath%>/jquery/jquery.timers.js"></script><!--定时器-->
<script type="text/javascript" src="<%=jsPath%>/terminalCommand.js?v=1"></script><!--终端命令结果查询-->
	
<script>
	/*
	修改代码：
	1.新定义变量TerminalCommmand，为命令支持变量
	2.重定义id：
	原：null		现：wmCommandMsg
	原：null		现：wmBtnQuery
	原：		现：
	*/

	var tc2WakeupMode = new TerminalCommand2();
    var timerName = "wakeupModeTimer";
    ///////////////////////////////////////////////////////////////
    tc2WakeupMode.messageDiv = $("#wmCommandMsg");
	tc2WakeupMode.timerName = timerName;
	//tc2WakeupMode.commandButton = $("#wmBtnQuery");

    //当查询终端参数命令执行成功时
    function onQueryCommandSuccess(result){
        if (result.success) {
            var p = result.data[0];
            var strArray = p.value.split(",");
            var i = 0;
            var wakeupMode = strArray[i++];
            setChecked("wakeupMode", wakeupMode ,3);
            var wakeupCondition = strArray[i++];
            setChecked("wakeupCondition", wakeupCondition ,3);
            var wakeupDay = strArray[i++];
            setChecked("wakeupDay", wakeupDay ,7);
            var enableTimeSpan = strArray[i++];
            setChecked("enableTimeSpan", enableTimeSpan ,4);
            var k = 1;
            for(var k = 1; k <= 4; k++)
			{
                var startTime = strArray[i++];
                var endTime = strArray[i++];
			    $("#startTime" + k).timespinner('setValue',startTime);
                $("#endTime" + k).timespinner('setValue',endTime);
			}

        }

    }

    function setChecked(name, v,len)
	{
	    var bitArray = parseInt(v).toString(2).split("").reverse();
	    for(var m = 0; m < len; m++)
		{
		    var checked = m < bitArray.length && bitArray[m] == "1";
            $("input[name='"+ name + "'][value='"+ m + "']").attr("checked", checked);
		}
	}


    /**
     * 下发参数查询指令
     */
    function sendParamQueryCommand()
    {
        operation = "query";
        var url = "<%=ApplicationPath%>/videoTerminalParam/sendParamQueryCommand.action";
        var param = {paramId : 0x007C,vehicleId:${vehicleId}};
        $.getJSON(url, param, function(result)
        {
            if (result.success) {
                var commandId = result.data; //下发成功后，获取到命令Id
                tc2WakeupMode.commandButton = $("#wmBtnQuery");
                var url = "<%=ApplicationPath%>/terminalParam/queryTerminalParam.action";
                tc2WakeupMode.times=190;
                tc2WakeupMode.startQueryResult(commandId,url,onQueryCommandSuccess);//命令下发成功,根据命令id,开始尝试获取检索结果

            }else {
                $("#wmCommandMsg").html("提交失败! 错误原因：" + (result.message ? result.message : result.Data));
                //停止所有的在$('body')上定时器
                $("#wmBody").stopTime (timerName);
            }
        });
    }

$().ready(function() {
	 $("#wmEntityForm").validate(); //初始化验证信息
	 Utility.ajaxSubmitForm("wmEntityForm", {
						 success:function(responseText)
						 {
							   var result = responseText;
								if (result.success) {
									 var commandId = result.data; //下发成功后，获取到命令Id

                                    tc2WakeupMode.commandButton = $("#wmBtnConfig");
									tc2WakeupMode.startQueryResult(commandId);//命令下发成功,根据命令id,开始尝试获取检索结果
								}
								else {
									$("#wmCommandMsg").html("提交失败! 错误原因：" + (result.message ? result.message : result.Data));
									//停止所有的在$('body')上定时器  
									$('#wmBody').stopTime (timerName);  
								  }
						 }
	 });

    $("#wmBtnQuery").click(function()
    {
        sendParamQueryCommand();//下发参数查询命令
    });
});
</script>
 <BODY id="wmBody">
	<form id="wmEntityForm" name="wmEntityForm" 
			action='<%=ApplicationPath%>/videoTerminalParam/configWakeupMode.action' method="POST">
				<!--超速设置-->
        <input type="hidden"  name="operation"  id="operation" value="modify"/>
        <input type="hidden"  name="vehicleId"  id="vehicleId" value="${vehicleId}"/>
  <table width="100%"  class="TableBlock">
					<tbody><tr>
						<td colspan="2" style="font-weight: bold; background: #EFEFEF;" height="25">终端休眠唤醒模式参数设置
						<span style="color:red;background:blue;">${message}</span>
						</td>
					</tr>
					
					<tr>
						<td align="right">休眠唤醒模式
							:</td>
						<td>
						<input type="checkbox" name="wakeupMode" value="0" />条件唤醒
							<input type="checkbox" name="wakeupMode" value="1" />定时唤醒
							<input type="checkbox" name="wakeupMode" value="2" />手动唤醒

						  </td>
					</tr>
					<tr>
						<td align="right">唤醒条件类型:</td>
						<td >

							<input type="checkbox" name="wakeupCondition" value="0" />紧急报警
							<input type="checkbox" name="wakeupCondition" value="1" />碰撞侧翻报警
							<input type="checkbox" name="wakeupCondition" value="2" />车辆开门

						</td>
					</tr>
					<tr>
						<td align="right" rowspan="2">定时唤醒日:</td>
						<td >

							<input type="checkbox" name="wakeupDay" value="0" />周一
							<input type="checkbox" name="wakeupDay" value="1" />周二
							<input type="checkbox" name="wakeupDay" value="2" />周三
							<input type="checkbox" name="wakeupDay" value="3" />周四
							<input type="checkbox" name="wakeupDay" value="4" />周五
							<input type="checkbox" name="wakeupDay" value="5" />周六
							<input type="checkbox" name="wakeupDay" value="6" />周日
						</td>
					</tr>
					<tr>
						<td >

							<input type="checkbox" name="enableTimeSpan" value="0" />时间段一
							<input id="startTime1" name="startTime" class="easyui-timespinner"  style="width:80px;"
								   required="required" data-options="min:'00:00',showSeconds:false" value="00:00">
							<input id="endTime1" name="endTime"  class="easyui-timespinner"  style="width:80px;"
								   required="required" data-options="min:'00:00',showSeconds:false" value="23:59">
						<br/>
							<input type="checkbox" name="enableTimeSpan" value="1" />时间段二
							<input id="startTime2" name="startTime"  class="easyui-timespinner"  style="width:80px;"
								   required="required" data-options="min:'00:00',showSeconds:false" value="00:00">
							<input id="endTime2" name="endTime"  class="easyui-timespinner"  style="width:80px;"
								   required="required" data-options="min:'00:00',showSeconds:false" value="23:59">
							<br/>
							<input type="checkbox" name="enableTimeSpan" value="2" />时间段三
							<input id="startTime3" name="startTime" class="easyui-timespinner"  style="width:80px;"
								   required="required" data-options="min:'00:00',showSeconds:false" value="00:00">
							<input id="endTime3" name="endTime"  class="easyui-timespinner"  style="width:80px;"
								   required="required" data-options="min:'00:00',showSeconds:false" value="23:59">
							<br/>
							<input type="checkbox" name="enableTimeSpan" value="3" />时间段四
							<input id="startTime4" name="startTime" class="easyui-timespinner"  style="width:80px;"
								   required="required" data-options="min:'00:00',showSeconds:false" value="00:00">
							<input id="endTime4" name="endTime"  class="easyui-timespinner"  style="width:80px;"
								   required="required" data-options="min:'00:00',showSeconds:false" value="23:59">
						</td>
					</tr>

					<tr>

						<td colspan=2 align="center">

							<button id="wmBtnConfig" type="submit" class="button green medium sendjson" ><i class="fa fa-cog" style="margin-right:3px;"></i> 设置参数</button>

							<button id="wmBtnQuery" type="button" class="button blue medium " ><i class="fa fa-reply-all" style="margin-right:3px;"></i> 查询参数</button>

							<span id="wmCommandMsg" class="commandMsg"></span></td>
						
					</tr>

				
					
				</tbody></table>
				</form>
 </BODY>
</HTML>
